# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=sq
pkgver=0.48.3
pkgrel=0
pkgdesc="CLI tool that provides jq-style access to structured data sources"
url="https://sq.io/"
# arm*, loongarch64, s390x, x86: tests fail
arch="all !armhf !armv7 !loongarch64 !s390x !x86"
license="MIT"
makedepends="go icu-dev"
checkdepends="tzdata"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/neilotoole/sq/archive/v$pkgver/sq-$pkgver.tar.gz"

export GOFLAGS="$GOFLAGS -tags=sqlite_vtable,sqlite_stat4,sqlite_fts5,sqlite_icu,sqlite_introspect,sqlite_json,sqlite_math_functions"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	local _goldflags="
		-X github.com/neilotoole/sq/cli/buildinfo.Version=v$pkgver
		-X github.com/neilotoole/sq/cli/buildinfo.Commit=RELEASE
		-X 'github.com/neilotoole/sq/cli/buildinfo.Timestamp=$(date -d @"$SOURCE_DATE_EPOCH" -u '+%Y-%m-%dT%H:%M:%SZ')'
		"

	go build -ldflags "$_goldflags"

	local shell; for shell in bash fish zsh; do
		./sq completion $shell > sq.$shell
	done

	./sq man > sq.1
}

check() {
	# shellcheck disable=2046
	go test -v $(go list ./... | grep -v /libsq/driver)
}

package() {
	install -Dvm755 sq -t "$pkgdir"/usr/bin/

	install -Dvm644 sq.bash \
		"$pkgdir"/usr/share/bash-completion/completions/sq
	install -Dvm644 sq.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/sq.fish
	install -Dvm644 sq.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_sq

	install -Dvm644 sq.1 \
		"$pkgdir"/usr/share/man/man1/sq.1
	install -Dvm644 LICENSE \
		"$pkgdir"/usr/share/licenses/sq/LICENSE
}

sha512sums="
93ba87fd929b2d749f4358bd0fec1c2d9cd7dc7f328ca0cdcb240d9d36c49a4773396af2fbe3623308e711b58919031b0c5ccbe7afe9bb0ee79f6fc93291acd3  sq-0.48.3.tar.gz
"
